package com.wmlive.hhvideo.heihei.mainhome.fragment;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.v4.os.ResultReceiver;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.PopupWindow;

import com.wmlive.hhvideo.common.AppCacheFileUtils;
import com.wmlive.hhvideo.common.GlobalParams;
import com.wmlive.hhvideo.common.base.DcBaseFragment;
import com.wmlive.hhvideo.common.navigator.Navigator;
import com.wmlive.hhvideo.common.network.HttpConstant;
import com.wmlive.hhvideo.heihei.beans.main.MultiTypeVideoBean;
import com.wmlive.hhvideo.heihei.beans.main.RefreshCommentBean;
import com.wmlive.hhvideo.heihei.beans.main.ShareInfo;
import com.wmlive.hhvideo.heihei.beans.main.ShortVideoInfoResponse;
import com.wmlive.hhvideo.heihei.beans.main.ShortVideoItem;
import com.wmlive.hhvideo.heihei.beans.main.ShortVideoLoveResponse;
import com.wmlive.hhvideo.heihei.beans.main.UserBehavior;
import com.wmlive.hhvideo.heihei.beans.personal.ReportType;
import com.wmlive.hhvideo.heihei.beans.splash.InitCatchData;
import com.wmlive.hhvideo.heihei.channel.ShareSdkUtils;
import com.wmlive.hhvideo.heihei.discovery.DiscoveryUtil;
import com.wmlive.hhvideo.heihei.discovery.activity.TopicActivity;
import com.wmlive.hhvideo.heihei.login.AccountUtil;
import com.wmlive.hhvideo.heihei.mainhome.activity.CommentActivity;
import com.wmlive.hhvideo.heihei.mainhome.activity.CommentListActivity;
import com.wmlive.hhvideo.heihei.mainhome.activity.MainNewActivity;
import com.wmlive.hhvideo.heihei.mainhome.adapter.RecommendNewAdapter;
import com.wmlive.hhvideo.heihei.mainhome.presenter.RecommendNewPresenter;
import com.wmlive.hhvideo.heihei.mainhome.presenter.ShortVideoViewCallback;
import com.wmlive.hhvideo.heihei.mainhome.presenter.UserInfoCallback;
import com.wmlive.hhvideo.heihei.personal.activity.WebViewActivity;
import com.wmlive.hhvideo.utils.CollectionUtil;
import com.wmlive.hhvideo.utils.KLog;
import com.wmlive.hhvideo.utils.MyClickListener;
import com.wmlive.hhvideo.utils.PopupWindowUtils;
import com.wmlive.hhvideo.utils.download.Download;
import com.wmlive.hhvideo.widget.dialog.CustomDialog;
import com.wmlive.hhvideo.widget.dialog.DownloadProgressDialog;
import com.wmlive.hhvideo.widget.dialog.MyDialog;
import com.wmlive.hhvideo.widget.dialog.MyDialogClickListener;
import com.wmlive.hhvideo.widget.refreshrecycler.OnFooterClickListener;
import com.wmlive.hhvideo.widget.refreshrecycler.RefreshRecyclerView;
import com.wmlive.networklib.util.RxBus;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.wmlive.hhvideo.R;
import cn.wmlive.hhvideo.rxbuslib.RxBus2;
import cn.wmlive.hhvideo.rxbuslib.RxBusSubscribe;
import cn.wmlive.hhvideo.rxbuslib.ThreadMode;

/**
 * Created by lsq on 6/22/2017.
 * 关注页面
 */

public class AttentionFragmentNew extends DcBaseFragment<RecommendNewPresenter> implements
        SwipeRefreshLayout.OnRefreshListener,
        RefreshRecyclerView.OnLoadMoreListener, RecommendNewPresenter.IRecommendView,
        ShortVideoViewCallback, PlatformActionListener, RecommendNewAdapter.OnActiveCallback {

    @BindView(R.id.recyclerView)
    RefreshRecyclerView recyclerView;
    private LinearLayoutManager linearLayoutManager;
    protected RecommendNewAdapter recommendAdapter;
    private PopupWindow shareWindow;
    //    protected SimpleListVideoUtil listVideoUtil;
    private boolean isActive;
    private MultiTypeVideoBean videoParam;

    protected int videoType = RecommendFragmentNew.TYPE_FOLLOW;//页面的视频类型
    private long typeId;//视频类型的id
    protected boolean isNeedPause = true;//如果是进入评论页面，不需要暂停

    private ShareInfo shareInfo;
    private long currentVideoId;//当前视频的id，只能作为举报作品和删除作品的时候使用
    private int currentVideoPosition;//当前位置
    private boolean isAttentionRecyclerIdle = true;

    public boolean isAttentionVisible = false;
    private UserInfoCallback userInfoCallback;
    private long currentUserId;//当前用户的id
    private MyDialog useMobileDialog;

    public static AttentionFragmentNew newInstance() {
        AttentionFragmentNew fragment = new AttentionFragmentNew();
        Bundle bundle = new Bundle();
        bundle.putBoolean(LAZY_MODE, true);
        bundle.putBoolean(SINGLE_MODE, true);
        bundle.putInt("videoType", RecommendFragmentNew.TYPE_FOLLOW);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    protected RecommendNewPresenter getPresenter() {
        return new RecommendNewPresenter(this);
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_recommend;
    }

    @Override
    protected void onSingleClick(View v) {

    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if (hidden) {
            pausePlay();
        } else {
            resumePlay();
        }
    }

    @Override
    protected void initData() {
        super.initData();
        recyclerView.setPageSnapEnable();
        if (null != getArguments()) {
            videoType = getArguments().getInt("videoType", RecommendFragmentNew.TYPE_FOLLOW);
        }
        linearLayoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.setOffset();
        recyclerView.setFooter(R.layout.view_recycler_main_load_more);
        recyclerView.setOnFooterClickListener(new OnFooterClickListener() {
            @Override
            public void onPageErrorClick() {
                super.onPageErrorClick();
                onRefresh();
            }

            @Override
            public void onFootErrorClick() {
                super.onFootErrorClick();
                onLoadMore();
            }
        });
        recommendAdapter = new RecommendNewAdapter(videoType, 4, new ArrayList<ShortVideoItem>(), recyclerView, linearLayoutManager, this);
        recommendAdapter.setShowImg(true);
        recommendAdapter.setEmptyStr(R.string.main_follow_null);
        recommendAdapter.setOnActiveCallback(this);
        recyclerView.setAdapter(recommendAdapter);
        recyclerView.setOnRefreshListener(this);
        recyclerView.setOnLoadMoreListener(this);
        recyclerView.getRecycleView().addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                isAttentionRecyclerIdle = (newState == 0);
                KLog.i("=====Recycler newState:" + newState + (isAttentionRecyclerIdle ? "停止" : "在滚动"));
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);

                KLog.i("=====Recycler dy:" + dy);
            }
        });
        recyclerView.autoRefresh(600);
    }


    @Override
    public void onRefresh() {
        isActive = false;
        presenter.getFollowList(true);
    }

    @Override
    public void onLoadMore() {
        presenter.getFollowList(false);
    }

    @Override
    public void onVideoListOk(boolean isRefresh, List<ShortVideoItem> list, boolean hasMore) {
        recommendAdapter.addDataList(isRefresh, list, hasMore);
    }

    @Override
    public void onVideoDetailOk(long videoId, int position, ShortVideoInfoResponse videoInfoBean) {
        dismissLoad();
        recommendAdapter.refreshVideoDetail(videoId, position, videoInfoBean);
    }

    @Override
    public void onVideoError(int position, long videoId, String message) {
        recommendAdapter.onVideoError(position, videoId, message);
    }

    @Override
    public void onReportListOk(List<ReportType> list) {
        InitCatchData.setReportEntry(list);
        if (currentVideoId > 0 && !CollectionUtil.isEmpty(list)) {
            if (AccountUtil.isLogin()) {
                showReportPop(list);
            } else {
                showReLogin();
            }
        } else {
            showToast(R.string.hintErrorDataDelayTry);
        }
    }

    @Override
    public void onLikeOk(long videoId, int position, ShortVideoLoveResponse bean) {
        recommendAdapter.refreshLike(position, videoId, bean);
        isAttentionRecyclerIdle = true;
    }

    @Override
    public void onReportOk() {
        showToast("举报成功");
    }

    @Override
    public void onFollowOk(int position, long videoId) {
        showToast("关注成功");
        recommendAdapter.refreshFollow(position, videoId);
        RxBus2.get().send(GlobalParams.EventType.TYPE_CONFIRM_FOLLOW, true);
    }

    @Override
    public void onDeleteVideoOk(final int position, long videoId) {
        showToast("删除作品成功");
        if (recommendAdapter.getDataContainer().size() > 1) {//个数大于1
            recommendAdapter.getDataContainer().remove(position);
            recommendAdapter.notifyItemRemoved(position);
            getWeakHandler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    int nextPosition = position;
                    if (position == (recommendAdapter.getDataContainer().size())) {//最后一个
                        nextPosition = (position - 1);
                    }
                    KLog.i("=====currentPosition:" + position);
                    KLog.i("=====nextPosition:" + nextPosition);
//                    recommendAdapter.forcePlay(nextPosition, true);
                }
            }, 800);
        } else {
            if (videoType == RecommendFragmentNew.TYPE_USER && typeId == AccountUtil.getUserId()) {//个人页
                getActivity().finish();
            } else {//非个人页
                recommendAdapter.addDataList(true, Collections.EMPTY_LIST);
            }
        }
    }

    @Override
    public void onRequestDataError(int requestCode, String message) {
        dismissLoad();
        if ((requestCode == HttpConstant.TYPE_FOLLOW_VIDEO_LIST)
                || (requestCode == HttpConstant.TYPE_FOLLOW_VIDEO_LIST + 1)) {
            recommendAdapter.showError(requestCode == HttpConstant.TYPE_FOLLOW_VIDEO_LIST);
            isAttentionRecyclerIdle = true;
        } else if (requestCode == HttpConstant.TYPE_VIDEO_INFO) {
            showToast("获取视频详情失败，请稍后再试");
        } else if (requestCode == HttpConstant.TYPE_REPORT_TYPE_LIST) {
            showToast("获取举报信息失败，请稍后再试");
        } else if (requestCode == HttpConstant.TYPE_REPORT) {
            showToast("举报失败，请稍后再试");
        } else if (requestCode == HttpConstant.TYPE_VIDEO_DELETE) {
            showToast("删除作品失败，请稍后再试");
        } else if (requestCode == HttpConstant.TYPE_VIDEO_LOVE) {
            showToast("点赞失败，请稍后再试");
        } else if (requestCode == HttpConstant.TYPE_USER_FOLLOW) {
            showToast("关注失败，请稍后再试");
        } else {
            super.onRequestDataError(requestCode, message);
        }
    }


    @Override
    public void getVideoDetail(int position, long id) {
        if (id > 0) {
//            loading();
            presenter.getVideoDetail(position, id);
        } else {
            showToast(R.string.hintErrorDataDelayTry);
        }
    }

    @Override
    public void getNextPageList(int position) {
        if (position > 0) {
            KLog.i("=====自动拉取下一页的数据");
            onLoadMore();
        }
    }

    @Override
    public void onUserAvatarClick(boolean isSelf, long userId) {
//        if (AccountUtil.getUserId() == userId || (videoType == TYPE_USER && userId == typeId)) {
//            return;
//        }
        Navigator.getInstance().navigateToOtherUserHome(getActivity(), true, userId);
    }

    @Override
    public void onFollowClick(int position, long videoId, long userId) {
        if (AccountUtil.isLogin()) {
            if (videoId > 0) {
                presenter.follow(position, videoId, userId);
            } else {
                showToast(R.string.hintErrorDataDelayTry);
            }
        } else {
            showReLogin();
        }

    }

    @Override
    public void onLikeClick(int position, long videoId) {
        if (AccountUtil.isLogin()) {
            if (videoId > 0) {
                presenter.likeVideo(position, videoId);
            } else {
                showToast(R.string.hintErrorDataDelayTry);
            }
        } else {
            showReLogin();
        }

    }

    @Override
    public void onShareClick(int position, long videoId, boolean isSelf, ShareInfo shareInfo) {
        this.shareInfo = shareInfo;
        this.currentVideoId = videoId;
        this.currentVideoPosition = position;
        if (isSelf) {
            shareWindow = PopupWindowUtils.showSelfShare(getRootView().getContext(), recyclerView, shareClickListener);
        } else {
            shareWindow = PopupWindowUtils.showOtherShare(getRootView().getContext(), recyclerView, shareClickListener);
        }
    }

    @Override
    public void onTopicClick(long topicId) {
        if (topicId > 0) {
            TopicActivity.startTopicActivity(getActivity(), topicId);
        } else {
            showToast(R.string.hintErrorDataDelayTry);
        }
    }

    @Override
    public void onMusicClick(long musicId) {
        if (musicId > 0) {
            TopicActivity.startMusicActivity(getActivity(), musicId);
        } else {
//            showToast(R.string.hintErrorDataDelayTry);  //暂且不处理
        }
    }

    @Override
    public void onCommentListShow(int position, boolean isRefresh, int count, long videoId) {
        isNeedPause = false;
        currentVideoPosition = position;
        CommentListActivity.startCommentListActivity(getContext(), videoType, position, count, videoId);
    }

    @Override
    public void onOpenCommentSend(int position, long videoId) {
        if (AccountUtil.isLogin()) {
            if (videoId > 0) {
                isNeedPause = false;
                currentVideoPosition = position;
                CommentActivity.startCommentActivity(getActivity(), false, position, videoId, null, 0);
            } else {
                showToast(R.string.hintErrorDataDelayTry);
            }
        } else {
            showReLogin();
        }
    }

    @Override
    public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
        showToast("分享成功");
        UserBehavior mUserBehavior = new UserBehavior(currentVideoId, 0, 1, 0);
        RxBus.getInstance().post(mUserBehavior);
    }

    @Override
    public void onError(Platform platform, int i, Throwable throwable) {
        showToast("分享失败");
    }

    @Override
    public void onCancel(Platform platform, int i) {
        showToast("取消分享");
    }

    private void showDeleteVideoDialog() {
        CustomDialog dialog = new CustomDialog(getActivity());
        dialog.setTitle("是否删除视频？");
        dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                presenter.deleteVideo(currentVideoPosition, currentVideoId);
                dialog.dismiss();
            }
        });
        dialog.show();
    }

    MyClickListener shareClickListener = new MyClickListener() {
        @Override
        protected void onMyClick(View v) {
            if (v.getId() == R.id.llManager) {
                String url = InitCatchData.opusManage();
                if (!TextUtils.isEmpty(url)) {
                    url = url + "?token=" + AccountUtil.getToken() + "&opus_id=" + currentVideoId;
                }
                WebViewActivity.startWebActivity(getActivity(), url, getString(R.string.pop_manager_title));

                if (null != shareWindow) {
                    shareWindow.dismiss();
                }
                return;
            }
            if (null != shareInfo) {
                switch (v.getId()) {
                    case R.id.llWeChat:
                        ShareSdkUtils.getInstance().showWechatShare(getActivity(), shareInfo, AttentionFragmentNew.this);
                        break;
                    case R.id.llCircle:
                        ShareSdkUtils.getInstance().showWechatMomentsShare(getActivity(), shareInfo, AttentionFragmentNew.this);
                        break;
                    case R.id.llWeibo:
                        ShareSdkUtils.getInstance().showWeiboShare(getActivity(), shareInfo, AttentionFragmentNew.this);
                        break;
                    case R.id.llQQ:
                        ShareSdkUtils.getInstance().showQQShare(getActivity(), shareInfo, AttentionFragmentNew.this);
                        break;
                    case R.id.llCopy:
                        ClipboardManager cmb = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                        cmb.setPrimaryClip(ClipData.newPlainText(null, shareInfo.getShare_url()));
                        showToast(R.string.copy_succeed);
                        break;
                    case R.id.llSave:
                        final DownloadProgressDialog downloadProgressDialog = new DownloadProgressDialog(getContext());
                        Download.start(getActivity()
                                , shareInfo.getDownload_link()
                                , AppCacheFileUtils.getAppExternalTempPath()
                                , ""
                                , new ResultReceiver(new Handler(Looper.getMainLooper())) {
                                    @Override
                                    protected void onReceiveResult(int resultCode, Bundle resultData) {
                                        super.onReceiveResult(resultCode, resultData);
                                        String savePath = null;
                                        if (null != resultData) {
                                            savePath = resultData.getString("savePath");
                                        }
                                        switch (resultCode) {
                                            case Download.RESULT_PREPARE:
                                                downloadProgressDialog.showDownload(new DialogInterface.OnDismissListener() {
                                                    @Override
                                                    public void onDismiss(DialogInterface dialog) {
                                                        Download.pause(getActivity());
                                                    }
                                                });
                                                downloadProgressDialog.updateProgress(0);
                                                break;
                                            case Download.RESULT_START:
                                                break;
                                            case Download.RESULT_PAUSE:
                                                downloadProgressDialog.dissmissDownload();
                                                break;
                                            case Download.RESULT_DOWNLOADING:
                                                if (null != resultData) {
                                                    downloadProgressDialog.updateProgress(resultData.getInt("percent"));
                                                }
                                                break;
                                            case Download.RESULT_ERROR:
                                                showToast("保存失败");
                                                downloadProgressDialog.dissmissDownload();
                                                break;
                                            case Download.RESULT_COMPLETE:
                                                showToast("保存成功");
                                                downloadProgressDialog.dissmissDownload();
                                                if (!TextUtils.isEmpty(savePath)) {
                                                    UserBehavior mUserBehavior = new UserBehavior(currentVideoId, 0, 0, 1);
                                                    RxBus.getInstance().post(mUserBehavior);
                                                    DiscoveryUtil.updateMedia(getActivity(), savePath);
                                                }
                                                break;
                                        }
                                    }
                                });
                        break;
                    case R.id.llDelete:
                        showDeleteVideoDialog();
                        break;
                    case R.id.llReport:
                        if (AccountUtil.isLogin()) {
                            List<ReportType> list = InitCatchData.getReportEntry();
                            if (!CollectionUtil.isEmpty(list)) {
                                if (currentVideoId > 0) {
                                    showReportPop(list);
                                } else {
                                    showToast(R.string.hintErrorDataDelayTry);
                                }
                            } else {
                                presenter.getReportType();
                            }
                        } else {
                            showReLogin();
                        }
                        break;
                }
                if (null != shareWindow) {
                    shareWindow.dismiss();
                }
            }
        }
    };

    //显示举报弹窗
    private void showReportPop(final List<ReportType> list) {
        if (!CollectionUtil.isEmpty(list)) {
            View view = LayoutInflater.from(getActivity()).inflate(R.layout.ppw_report_works, null);
            ListView listView = (ListView) view.findViewById(R.id.lvReportList);
            final PopupWindow popupWindow = PopupWindowUtils.createPopWindowFromBottom(recyclerView, view);
            view.findViewById(R.id.tvCancel).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    popupWindow.dismiss();
                }
            });

            List<String> stringList = new ArrayList<>();
            final List<ReportType> reportTypes = new ArrayList<>();
            for (ReportType reportType : list) {
                if (reportType.getResource() == 0) {
                    reportTypes.add(reportType);
                    stringList.add(reportType.getDesc());
                }
            }
            listView.setAdapter(new ArrayAdapter<>(getActivity(), R.layout.item_report_works, stringList.toArray(new String[stringList.size()])));
            listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    presenter.reportWorks(currentVideoPosition, currentVideoId, reportTypes.get(position).getId());
                    popupWindow.dismiss();
                }
            });
        } else {
            showToast(R.string.hintErrorDataDelayTry);
        }
    }

    @Override
    public void onDestroy() {
        RxBus2.get().unRegister(this);
        userInfoCallback = null;
        if (null != recommendAdapter) {
            recommendAdapter.releasePlayer();
        }
        super.onDestroy();
    }


    @Override
    public void beforePlay() {
        KLog.i("=====关注页面是否可见");
        isAttentionRecyclerIdle = true;
        if (!isAttentionVisible && null != recommendAdapter) {
            KLog.i("=====页面不可见，不能播放");
            recommendAdapter.pausePlay();
        }
    }


    /**
     * 设置获取用户信息的回调
     *
     * @param userInfoCallback
     */
    public void setUserInfoCallback(UserInfoCallback userInfoCallback) {
        this.userInfoCallback = userInfoCallback;
    }

    public long getUserId() {
        return currentUserId;
    }

    @Override
    public void getUserInfo(long userId) {
        currentUserId = userId;
        if (null != userInfoCallback) {
            userInfoCallback.getUserInfo(userId);
        }
    }

    @Override
    public void onFragmentInvisible() {//嵌套中切换不可见
        super.onFragmentInvisible();
        isAttentionVisible = false;
        pausePlay();
    }

    @Override
    public void onFragmentVisible() {//嵌套中切换可见
        isAttentionVisible = true;
        resumePlay();
    }

    @Override
    public void onMobileNetwork() {
        if (isLoadFinish && recommendAdapter != null) {
            showUseMobileNetwork();
        }
    }

    //显示是否使用移动网络播放视频
    public void showUseMobileNetwork() {
        if (useMobileDialog == null) {
            useMobileDialog = new MyDialog("", getString(R.string.stringMobileNetworkHint), "是", "否", false, new MyDialogClickListener() {
                @Override
                public void onPositiveClick(DialogInterface dialog, int which) {
                    super.onPositiveClick(dialog, which);
                    GlobalParams.StaticVariable.sAllowdMobile = true;
                    if (recommendAdapter != null) {
                        recommendAdapter.allowPlay();
                    }
                }

                @Override
                public void onNegativeClick(DialogInterface dialog, int which) {
                    super.onNegativeClick(dialog, which);
                    GlobalParams.StaticVariable.sAllowdMobile = false;
                    if (recommendAdapter != null) {
                        recommendAdapter.disallowPlay();
                    }
                }
            });
        }
        if (!useMobileDialog.isShowing()) {
            useMobileDialog.show(getActivity());
        }
    }

    @Override
    public void onStart() {
        RxBus2.get().register(this);
        super.onStart();
    }

    @Override
    public void onResume() {
        super.onResume();
        isAttentionVisible = true;
        resumePlay();
    }

    @Override
    public void onPause() {
        super.onPause();
        isAttentionVisible = false;
        pausePlay();
    }

    /**
     * 是否处于停止滚动状态
     *
     * @return
     */
    public boolean isRecyclerIdle() {
        return isAttentionRecyclerIdle;
    }

    public void resumePlay() {
        if (isLoadFinish && HomeFragment.currentTabPosition == 0 && MainNewActivity.currentPage == 0 && null != recommendAdapter) {
            if (GlobalParams.StaticVariable.sCurrentNetwork == 1 && !GlobalParams.StaticVariable.sAllowdMobile) {//处于移动网络且不允许播放
                return;
            }
            KLog.i("=====关注页面继续播放");
            recommendAdapter.resumePlay();
            if (GlobalParams.StaticVariable.sCurrentNetwork == 0) {
                if (useMobileDialog != null) {
                    useMobileDialog.dismiss();
                }
            }
        }
    }

    public void pausePlay() {
        if (isLoadFinish && null != recommendAdapter) {
            KLog.i("=====关注页面暂停播放");
            recommendAdapter.pausePlay();
        }
    }

    //刷新评论数量
    @RxBusSubscribe(code = GlobalParams.EventType.TYPE_REFRESH_RECOMMEND_COMMENT_COUNT, threadMode = ThreadMode.MAIN)
    public void onCommentEvent(RefreshCommentBean commentBean) {
        if (null != commentBean && null != recommendAdapter) {
            recommendAdapter.refreshCommentCount(commentBean);
        }
    }

    //显示封面
    @RxBusSubscribe(code = GlobalParams.EventType.TYPE_SHOW_VIDEO_COVER, threadMode = ThreadMode.MAIN)
    public void onShowCoverEvent(Boolean show) {
        if (isLoadFinish && !isAttentionVisible && null != recommendAdapter) {
            recommendAdapter.showVideoCover(true);
        }
    }

    @RxBusSubscribe(code = GlobalParams.EventType.TYPE_WORK_DELETED, threadMode = ThreadMode.MAIN)
    public void onWorkDeletedEvent(Long videoId) {
        if (recommendAdapter != null) {
            recommendAdapter.onVideoError(currentVideoPosition, videoId, "");
        }
    }

    @Override
    public void onActive() {
        if (!isActive && null != recommendAdapter) {
            KLog.i("====激活播放");
            getWeakHandler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    recommendAdapter.forcePlay(true);
                }
            }, 200);
            isActive = true;
        }
    }
}
